<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <!--以最新的IE浏览器引擎去渲染-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <!--如果是双核浏览器，则使用webkit内核渲染-->
    <meta name="renderer" content="webkit"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title></title>
    <meta name="description" content=""/>
    <meta name="keyword" content=""/>
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
    <link rel="stylesheet" href="__PUBLIC__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/frame/static/css/style.css">
    <script type="text/javascript" src="__PUBLIC__/js/jquery1.12.4.js"></script>
    <script type="text/javascript" src="__PUBLIC__/frame/layui/layui.js"></script>
    <link rel="icon" href="__PUBLIC__/frame/static/image/code.png">
</head>
<body>
<style>
    .box{
        margin-top: 20px;
        margin-left: 20px;
    }
    .sum{
        float: right;
        margin-right: 20px;
        line-height: 32px;
    }
    .quanxian{
        display: inline-block;
        width: 200px;
    }
    .addquanxian{
        display: inline-block;
        float: left;
    }
    .juzhong{
        width: 270px;
        margin: 0 auto;
    }
    .refresh{
        display: inline-block;
        float: right;
        margin-right: 20px;
    }
</style>
<div class="box">
    <button class="layui-btn layui-btn-normal addquanxian">添加管理员</button>
    <button class="layui-btn layui-btn-normal refresh" onclick="refresh()" title="刷新"><i class="layui-icon">&#x1002;</i></button>
    <div class="layui-input-block juzhong">
        <input type="text" name="title" autocomplete="off" placeholder="请输入管理员名称" class="layui-input quanxian">
        <button class="layui-btn layui-btn-normal"><i class="layui-icon">&#xe615;</i></button>
    </div>

    <span class="sum">共有数据：<strong><?php echo $count ?></strong> 条</span>
</div>
<div class="layui-fluid">
    <table class="layui-table" style="text-align: center">
        <thead>
        <tr>
            <th style="text-align: center">ID</th>
            <th style="text-align: center">登录名</th>
            <th style="text-align: center">真实姓名</th>
            <th style="text-align: center">手机</th>
            <th style="text-align: center">邮箱</th>
            <th style="text-align: center">角色</th>
            <th style="text-align: center">上次登录时间</th>
            <th style="text-align: center">是否已启用</th>
            <th style="text-align: center">操作</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($data as $v){?>
        <tr>
            <td><?php echo $v['id'];?></td>
            <td><?php echo $v['username'];?></td>
            <td><?php echo $v['realname'];?></td>
            <td><?php echo $v['phonenumber']?></td>
            <td><?php echo $v['email']?></td>
            <td><?php echo $v['role_name']?></td>
            <td><?php echo date("Y-m-d H:i:s",$v['lastlogintime'])?></td>
            <td>
                <?php if($v['is_use']==1){?>
                <button onclick="adminStop(this,<?php echo $v['id'];?>)" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe610;</i>启用</button>
                <?php }else{?>
                <button  onclick="adminStart(this,<?php echo $v['id'];?>)" class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon">&#x1005;</i>禁用</button>
                <?php }?>
            </td>
            <td>
                <a href="javascript:void (0);" onclick="admin_permission_edit(<?php echo $v['id']?>)"><i class="layui-icon">&#xe642;</i></a>
                <a href="javascript:void (0);" onclick="admin_permission_del(this,<?php echo $v['id']?>)"><i class="layui-icon">&#xe640;</i></a>
            </td>
        </tr>
        <?php }?>
        <tr><td colspan="9" style="text-align: right"><?php echo $page ?></td></tr>
        </tbody>
    </table>
</div>

<script type="text/javascript">
    var layer = '';
    layui.use(['layer'],function () {
        layer = layui.layer;
        $('.addquanxian').click(function () {
            layer.open({
                type: 2,
                title: '添加角色',
                shadeClose: true,
                shade: 0.5,
                maxmin: true, //开启最大化最小化按钮
                area: ['800px', '560px'],
                content: '/index.php/home/admin/admin_add'
            });
        })
    });

    function adminStop(obj,id) {
        layer.confirm('确认要停用吗?',function (index) {
            if(id=='1'){
                layer.msg('超级管理不能被禁用');
                return false;
            }
            var url = '/index.php/home/admin/updateis_use';
            var data = {'id':id,'is_use':0};
            $.post(url,data,function(result){
                if(result.status=='1'){  //成功
                    $(".refresh").click();
                    layer.msg('已停用!',{icon: 5,time:1000});
                }else{
                    layer.msg('停用失败');
                }
            },"JSON")
        })
    }
    function adminStart(obj,id) {
        layer.confirm('确认要启用吗？',function (index) {
            var url = '/index.php/home/admin/updateis_use';
            var data = {'id':id,'is_use':1};
            $.post(url,data,function(result){
                if(result.status=='1'){  //成功
                    $(".refresh").click();
                    layer.msg('已启用!', {icon: 6, time: 1000});
                }else{
                    layer.msg('启用失败');
                }
            },"JSON")
        })
    }


    //页面刷新
    function refresh() {
        location.replace(location.href);
    }

    //编辑
    function admin_permission_edit(id) {
        layer.open({
            type: 2,
            title: '编辑管理员',
            shadeClose: true,
            shade: 0.5,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '560px'],
            content: '/index.php/home/admin/edit?id='+id
        })
    }

    //删除
    function admin_permission_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            var url = "/index.php/Home/admin/del";
            var data = {id:id};
            $.post(url,data,function(result){
                if(result.status == 1){
                    $(obj).parents("tr").remove();
                    layer.msg(result.message,{icon:1,time:1000});
                }
                if(result.status == 0){
                    layer.msg(result.message);
                }
            },"JSON");
        });
    }
</script>

</body>